<#include "/WEB-INF/default/fragment/header.ftl">
<body>

<#include "/WEB-INF/default/fragment/nav.ftl">

<div class="container">

<div class="tms-logo"><img class="center-block" src="${request.contextPath}/assets/images/logo.png" alt=""></div>

<form class="j_register_form" action="${request.contextPath}/register-step3.action" method="post">
    <fieldset>
        <legend>
          <#assign registerStepIndex=2 >
          <#include "/WEB-INF/default/fragment/register_steps.ftl">
        </legend>
        <div class="form-group">
            <label for="exampleInputEmail1">邮箱</label>
            <#if user?exists && user['email']?exists>
            <p class="help-block text-success">${user['email']}</p>
            </#if>
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">激活码</label>
            <input type="text" class="form-control" name="user.vercode" placeholder="请输入邮箱中接收的  6 位数字验证码">
            <p class="help-block">${fieldErrors['user.vercode']!""}</p>
        </div>

        <button type="submit" class="btn btn-block btn-success j_register_form_submit">立即注册</button>
        <a href="${request.contextPath}/register-step2.action">上一步</a>
    </fieldset>
</form>

</div>

<script>
$(document).on('submit', '.j_register_form', function() {
  var param = $('.j_register_form').serialize();
  param = param + '&struts.enableJSONValidation=true';
  $('.j_register_form_submit').button('loading');
  $.post('${request.contextPath}/register-step3.action', param, function(data, textStatus, xhr) {
    $('.j_register_form_submit').button('reset');

    // { "fieldErrors": {"username":["\u7528\u6237\u540D\u4E0D\u80FD\u4E3A\u7A7A"],"passwd":["\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"]}}
    if(data['fieldErrors'] != null) {
      for (var i in data['fieldErrors']) {
        $('input[name="'+i+'"]').next().html(data['fieldErrors'][i]);
      }
      return;
    }

    if (data['status'] === 1) { // 恒等于，数据类型和值都相等
      window.location.href = '${request.contextPath}/login-index.action';
    }
    if (data['status'] !== 1) { // 恒等于，数据类型和值都相等
      alert(data['message']);
    }

    console.log(data);
  });
  return false;
});
</script>

</body>
<#include "/WEB-INF/default/fragment/footer.ftl">
